From 91bb91dbb9e10691a9f4e3e8f0b1b4dabcd7ee27 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?utf8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Wed, 30 Dec 2015 18:05:05 +0000 Subject: [PATCH] Fix to compile for C libraries with no flockfile Also use MS variant of flockfile, if available (requires MSVCRT compatible with MSVCR90 or newer). --- configure.ac | 2 +- gtk/gtkimmodule.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 89d00d792e..fb27eaac66 100644 --- a/configure.ac +++ b/configure.ac @@ -413,7 +413,7 @@ AC_SUBST(DISABLE_ON_QUARTZ) AC_CHECK_LIB([rt], [shm_open], [SHM_LIBS="-lrt"], [SHM_LIBS=""]) AC_SUBST(SHM_LIBS) -AC_CHECK_FUNCS(posix_fallocate) +AC_CHECK_FUNCS(posix_fallocate flockfile _lock_file) if test "x$enable_broadway_backend" = xyes; then GDK_BACKENDS="$GDK_BACKENDS broadway" diff --git a/gtk/gtkimmodule.c b/gtk/gtkimmodule.c index 405d87626f..47e6348ebe 100644 --- a/gtk/gtkimmodule.c +++ b/gtk/gtkimmodule.c @@ -64,6 +64,23 @@ #include "deprecated/gtkrc.h" +/* We need to call getc() a lot in a loop. This is suboptimal, + * as getc() does thread locking on the FILE it is given. + * To optimize that, lock the file first, then call getc(), + * then unlock. + * If locking functions are not present in libc, fall back + * to the suboptimal getc(). + */ +#if !defined(HAVE_FLOCKFILE) && !defined(HAVE__LOCK_FILE) +# define flockfile(f) (void)1 +# define funlockfile(f) (void)1 +# define getc_unlocked(f) getc(f) +#elif !defined(HAVE_FLOCKFILE) && defined(HAVE__LOCK_FILE) +# define flockfile(f) _lock_file(f) +# define funlockfile(f) _unlock_file(f) +# define getc_unlocked(f) _getc_nolock(f) +#endif + #define SIMPLE_ID "gtk-im-context-simple" #define NONE_ID "gtk-im-context-none" -- 2.30.2